const request = (obj) => {
	let httpDefaultOpts = {
		url: obj.url,
		data: obj.data || {},
		method: obj.method || 'POST',
		header: {
			'content-type': obj.contentType ? obj.contentType : 'application/json', // 默认值
			'platform-type': 'SHOP_KEEPER',
			'pageNum': obj.headerData ? obj.headerData.pageNum : '',
			'pageSize': obj.headerData ? obj.headerData.pageSize : '',
			'token': uni.getStorageSync('token')?uni.getStorageSync('token'):''
		}
	}
	let promise = new Promise(function(resolve, reject) {
		uni.request(httpDefaultOpts).then(
			(res) => {
				resolve(res[1])
			}
		).catch(
			(response) => {
				reject(response)
			}
		)
	})
	return promise
}

const fileRequest = (obj) => {
	let httpDefaultOpts = {
		url: obj.url,
		filePath: obj.filePath || {},
		name: 'file',
		header: {
			'platform-type': 'SHOP_KEEPER',
			'token': 'eyJhbGciOiJIUzI1NiJ9.eyJwbGF0Zm9ybVR5cGUiOiJTSE9QX0tFRVBFUiIsImV4cCI6MTU3NDY5ODg3MiwidXNlcklkIjoiMTMiLCJpYXQiOjE1NzQ2NjczMzYsImp0aSI6InRva2VuSWQifQ.IRWUnsI4aVMdQelTaB53qIlIlJYb9ZWzYEKm_3NTpKM'
		}
	}
	let promise = new Promise(function(resolve, reject) {
		uni.uploadFile(httpDefaultOpts).then(
			(res) => {
				resolve(res[1])
			}
		).catch(
			(response) => {
				reject(response)
			}
		)
	})
	return promise
}

module.exports = {
	request: request,
	fileRequest: fileRequest
}
